package com.hualan.controller;

import com.hualan.pojo.Result;
import com.hualan.utils.VideoUploadUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.io.IOException;


@RestController
public class VideoUploadController {

    private final VideoUploadUtil videoUploadUtil;
    public VideoUploadController( VideoUploadUtil videoUploadUtil) {
        this.videoUploadUtil = videoUploadUtil;
    }
    @PostMapping("/upload/video")
    public Result uploadVideo(@RequestParam("file") MultipartFile file) {
        try {
            // 检查文件大小是否超过 200MB
            if (file.getSize() > 200 * 1024 * 1024) {
                return Result.error("视频文件大小不能超过 200MB");
            }
            // 创建上传目录
            String fileUrl = videoUploadUtil.upload(file);
            return Result.success(fileUrl);
        } catch (IllegalArgumentException e) {
            return Result.error(e.getMessage());
        } catch (IOException e) {
            return Result.error("上传失败: " + e.getMessage());
        }
    }
}


